export function timeStamp(value) {
	if (!value) return '';
	var now = new Date(value);
	var year = now.getFullYear();
	var month = now.getMonth() + 1;
	if (month < 10) {
		month = '0' + month
	}
	var date = now.getDate();
	if (date < 10) {
		date = '0' + date
	}
	return year + "-" + month + "-" + date
}

export function timeDate(value) {
	if (!value) return '';
	var now = new Date(value * 1000);

	var month = now.getMonth() + 1;
	if (month < 10) {
		month = '0' + month
	}
	var date = now.getDate();
	if (date < 10) {
		date = '0' + date
	}
	return month + "-" + date
}

export function timeMinute(value) {
	if (!value) return '';
	var now = new Date(value * 1000);

	var month = now.getMonth() + 1;
	if (month < 10) {
		month = '0' + month
	}
	var date = now.getDate();
	if (date < 10) {
		date = '0' + date
	}
	var hour = now.getHours();
	if (hour < 10) {
		hour = '0' + hour
	}
	var minute = now.getMinutes();
	if (minute < 10) {
		minute = '0' + minute
	}
	return month + "-" + date + "-" + hour + "-" + minute
}

export function yearMonthDateMinSec(value) {
	if (!value) return '';
	var now = new Date(value);
	var year = now.getFullYear();
	var month = now.getMonth() + 1;
	if (month < 10) {
		month = '0' + month
	}
	var date = now.getDate();
	if (date < 10) {
		date = '0' + date
	}
	var hour = now.getHours();
	if (hour < 10) {
		hour = '0' + hour
	}
	var minute = now.getMinutes();
	if (minute < 10) {
		minute = '0' + minute
	}
	var second = date.getSeconds()
	if (second < 10) {
		second = '0' + second
	}
	return year + "-" + month + "-" + date + " " + hour + ":" + minute + ':' + second
}


/**
 * 格式化日期格式
 * @param value
 * @param formatType
 * @param isUninx
 * @returns {string|*}
 */
export function formatDate(
	value, formatType = 's', isUninx = false) {
	if (formatType == 's') {
		formatType = 'YYYY-MM-DD HH:mm:ss'
	} else if (formatType == 'd') {
		formatType = 'YYYY-MM-DD'
	} else if (formatType == 'm') {
		formatType = 'YYYY-MM-DD HH:mm'
	} else if (formatType == 'y') {
		formatType = 'YYYY'
	} else if (formatType == 'month') {
		formatType = 'YYYY-MM'
	}
	if (value) {
		if (isUninx) {
			return moment.unix(value).format(formatType)
		} else {
			return moment(value).format(formatType)
		}
	} else {
		return ''
	}
}
